#include "apue.h"

int main(void) {
    int n, int1, int2;
    char line[MAXLINE];
    char debug[MAXLINE];

    while ((n= read(STDIN_FILENO, line, MAXLINE)) > 0) {
        line[n]= 0;     /* null terminate */
        if (sscanf(line, "%d%d", &int1, &int2) == 2) {
            sprintf(line, "%d\n", int1+int2);
            n= strlen(line);
            
            //strcpy(debug, "echo -n '");
            //strcpy(debug+strlen(debug), line);
            //strcpy(debug+strlen(debug), "' >> kakaxi.txt");
            //system(debug);

            if (write(STDOUT_FILENO, line, n) != n)
                err_sys("write error");

        } else {
            if (write(STDOUT_FILENO, "invalid args\n", 13) != 13) 
                err_sys("write error");
        }
    }
    exit(0);
}
